var arr = [3, 5, 7, 1, 4, 56, 12, 78, 25, 0, 9, 3, 8, 42, 37];

console.time('time')
function mergeSort(arr) {
  if (arr.length < 2) return arr;
  const midK = Math.floor(arr.length / 2);
  let left = arr.slice(0, midK),
    right = arr.slice(midK);

  return merge(mergeSort(left), mergeSort(right));
}
function merge(left, right) {
  let result = [];
  while (left.length > 0 && right.length > 0) {
    if (left[0] > right[0]) {
      result.push(right.shift());
    } else {
      result.push(left.shift());
    }
  }
  while (left.length > 0) {
    result.push(left.shift());
  }
  while (right.length > 0) {
    result.push(right.shift());
  }
  return result;
}

console.log(mergeSort(arr));
console.timeEnd('time')
